hysop.fields.continuous_field module

Continuous fields description and containers. * FieldContainerI * ScalarField * VectorField * TensorField

hysop.fields.continuous_field.Field

A Field is just a alias of FieldContainerI

class hysop.fields.continuous_field.FieldContainerI(domain, name=None, nb_components=None, shape=None, is_vector=None, **kwds)[source]

Bases: TaggedObject

Common abstract interface for scalar and tensor-like fields.

Initialize a TaggedObject with a tag prefix/postfix/formatter, all optional.

static __new__(cls, domain, name=None, nb_components=None, shape=None, is_vector=None, **kwds)[source]

Create a FieldContainer on a specific domain. domain : domain.Domain

Physical domain where this field is defined.

kwds: dict

Keywords arguments for base class.

Notes

This can also be used to instantiate a ScalarField, VectorField or TensorField depending on nb_components, shape and is_vector.

property boundaries

Try to return the unique boundaries common to all contained fields, else raise an AttributeError.

property boundaries_kind

Try to return the unique boundaries kind common to all contained fields, else raise an AttributeError.

curl(name=None, pretty_name=None, scalar_name_prefix=None, scalar_pretty_name_prefix=None, dtype=None, **kwds)[source]

Create a field capable of storing the curl of self,

Only 2D and 3D fields are supported as the curl brings a 1-vector to a 2-vector:

  • A vector to a pseudoscalar or a pseudoscalar to a vector in 2D

  • A vector to a pseudovector or a pseudovector to a vector in 3D

In 1D the curl is 0, and in 4D the curl would be a 6D ‘field’.

property dim

Return the dimension of the physical domain.

abstract discretize(topology, topology_state=None)[source]

Discretization of the field on a given topology.

Parameters:
  • topology (hysop.mpi.core.topology.Topology) – The topology on which to discretize this ScalarField.

  • state (hysop.mpi.core.topology.TopologyState, optional) – The topology state on which to discretize this ScalarField.

div(name=None, pretty_name=None, scalar_name_prefix=None, scalar_pretty_name_prefix=None, axis=-1, dtype=None, **kwds)[source]

Create a field capable of storing the divergence of self, on chosen axis.

property domain

Return the physical domain where this field is defined.

property dtype

Try to return the unique data type common to all contained fields, else raise an AttributeError.

abstract field_like(name, **kwds)[source]

Create a ScalarField like this object, possibly altered.

abstract fields()[source]

Return all unique scalar fields contained in this field container.

classmethod from_sympy_expression(expr, space_symbols, **kwds)[source]
classmethod from_sympy_expressions(name, exprs, space_symbols, scalar_name_prefix=None, scalar_pretty_name_prefix=None, pretty_name=None, **kwds)[source]

Create a field wich has the same shape as exprs, with optional names. Expressions should be of kind sympy.Expr and are converted to FieldExpression: this means they all have to contain at least one FieldExpression. Note that field.symbol is always a SymbolicField which is a FieldExpression. FieldExpression make sure boundary conditions match between fields for derivatives and integrations.

get_attributes(*attrs)[source]

Return all matching attributes contained in self.fields, as a tuple.

get_unique_attribute(*attr)[source]

Try to return the unique attribute common to all contained fields. Raise an AttributeError if a attribute is not unique accross contained field views.

gradient(name=None, pretty_name=None, scalar_name_prefix=None, scalar_pretty_name_prefix=None, directions=None, axis=-1, space_symbols=None, dtype=None, **kwds)[source]

Create a field capable of storing the gradient of self, possibly altered.

has_unique_attribute(*attr)[source]

Return true if all contained fields share the same attribute (as stated by the == comparisson operator).

has_unique_boundaries()[source]

Return true if all contained continuous fields share the same boundaries.

has_unique_boundaries_kind()[source]

Return true if all contained continuous fields share the same boundaries kind.

has_unique_dtype()[source]

Return true if all contained discrete fields share the same dtype.

has_unique_lboundaries()[source]

Return true if all contained continuous fields share the same lboundaries.

has_unique_lboundaries_kind()[source]

Return true if all contained continuous fields share the same lboundaries kind.

has_unique_periodicity()[source]

Return true if all contained continuous fields share the same periodicity.

has_unique_rboundaries()[source]

Return true if all contained continuous fields share the same rboundaries.

has_unique_rboundaries_kind()[source]

Return true if all contained continuous fields share the same rboundaries kind.

property is_scalar
laplacian(name=None, pretty_name=None, scalar_name_prefix=None, scalar_pretty_name_prefix=None, dtype=None, **kwds)[source]
property lboundaries

Try to return the unique lboundaries common to all contained fields, else raise an AttributeError.

property lboundaries_kind

Try to return the unique lboundaries common to all contained fields, else raise an AttributeError.

abstract nb_components()[source]

Total number of components of this field container, exluding None entries, but including duplicate fields.

property periodicity

Try to return the unique periodicity common to all contained fields, else raise an AttributeError.

property rboundaries

Try to return the unique rboundaries common to all contained fields, else raise an AttributeError.

property rboundaries_kind

Try to return the unique rboundaries common to all contained fields, else raise an AttributeError.

rot(*args, **kwds)[source]

See curl.

abstract tmp_like(name, **kwds)[source]

Create a temporary field like self, possibly altered.

class hysop.fields.continuous_field.ScalarField(domain, name, pretty_name=None, var_name=None, latex_name=None, initial_values=None, dtype=<class 'numpy.float64'>, lboundaries=None, rboundaries=None, is_tmp=False, mem_tag=None, **kwds)[source]

Bases: NamedScalarContainerI, FieldContainerI

A continuous field is a scalar field defined on a physical domain.

This object handles a dictionnary of discrete fields (from 0 to any number).

Each discrete field is uniquely defined by the topology used to discretize it.

Example

If topo1 and topo2 are two hysop.topology.cartesian_topology.Topology instances:

scal = ScalarField(domain=dom, name=’Scalar’)

# Discretize the field on the two topologies: scal.discretize(topo1) scal.discretize(topo2)

# Access the discrete fields: scal_discr1 = scal.discrete_fields[topo1] scal_discr2 = scal.discrete_fields[topo2]

Create or get an existing continuous ScalarField (scalar or vector) on a specific domain.

Parameters:
  • domain (domain.Domain) – Physical domain where this field is defined.

  • name (string) – A name for the field.

  • pretty_name (str, optional.) – A pretty name used for display whenever possible. Defaults to name.

  • var_name (string, optional.) – A variable name used for code generation. This will be passed to the symbolic representation of this field.

  • latex_name (string, optional.) – A variable name used for latex generation. This will be passed to the symbolic representation of this field.

  • dtype (npw.dtype, optional, defaults to HYSOP_REAL) – Underlying data type of this field

  • initial_values (numeric value, or tuple of numeric values, optional) –

    Fields are initialized to specified initial value everywhere in the domain on first discretization. The input values are cast to given dtype.

    If None, leaves the memory uninitialized. If a single value is given, the whole field is initialized to this value,

    the default being None (ie. no initialization at all).

    If tuple, computational mesh will be initialized with the first value,

    and ghosts will be initialized with the second value.

  • lboundaries (array_like of BoundaryCondition or BoundaryConditionConfig, optional) – Left boundary conditions, defaults to PERIODIC on each axis.

  • rboundaries (array_like of BoundaryCondition or BoundaryConditionConfig, optional) – Right boundary conditions, defaults to PERIODIC on each axis.

  • is_tmp (bool) –

    Specify that this field is a temporary continuous field. Basically a ScalarField that yields a temporary discrete field upon discretization.

    /!** WARNING ***************************************/!TemporaryDiscreteFields are allocated during setup using temporary work buffers. Those work buffers are only available withing the scope of operators thats use this temporary field during their apply method. /!************************************************* /!

  • kwds (dict) – Base class keyword arguments.

boundaries

Left and right boundary conditions as a tuple.

Type:

tuple of numpy.ndarray of BoundaryCondition

periodicity

Numpy array mask, True is axis is periodic, else False.

Type:

numpy.ndarray of bool

static __new__(cls, domain, name, pretty_name=None, var_name=None, latex_name=None, initial_values=None, dtype=<class 'numpy.float64'>, lboundaries=None, rboundaries=None, is_tmp=False, mem_tag=None, **kwds)[source]

Create or get an existing continuous ScalarField (scalar or vector) on a specific domain.

Parameters:
  • domain (domain.Domain) – Physical domain where this field is defined.

  • name (string) – A name for the field.

  • pretty_name (str, optional.) – A pretty name used for display whenever possible. Defaults to name.

  • var_name (string, optional.) – A variable name used for code generation. This will be passed to the symbolic representation of this field.

  • latex_name (string, optional.) – A variable name used for latex generation. This will be passed to the symbolic representation of this field.

  • dtype (npw.dtype, optional, defaults to HYSOP_REAL) – Underlying data type of this field

  • initial_values (numeric value, or tuple of numeric values, optional) –

    Fields are initialized to specified initial value everywhere in the domain on first discretization. The input values are cast to given dtype.

    If None, leaves the memory uninitialized. If a single value is given, the whole field is initialized to this value,

    the default being None (ie. no initialization at all).

    If tuple, computational mesh will be initialized with the first value,

    and ghosts will be initialized with the second value.

  • lboundaries (array_like of BoundaryCondition or BoundaryConditionConfig, optional) – Left boundary conditions, defaults to PERIODIC on each axis.

  • rboundaries (array_like of BoundaryCondition or BoundaryConditionConfig, optional) – Right boundary conditions, defaults to PERIODIC on each axis.

  • is_tmp (bool) –

    Specify that this field is a temporary continuous field. Basically a ScalarField that yields a temporary discrete field upon discretization.

    /!** WARNING ***************************************/!TemporaryDiscreteFields are allocated during setup using temporary work buffers. Those work buffers are only available withing the scope of operators thats use this temporary field during their apply method. /!************************************************* /!

  • kwds (dict) – Base class keyword arguments.

boundaries

Left and right boundary conditions as a tuple.

Type:

tuple of numpy.ndarray of BoundaryCondition

periodicity

Numpy array mask, True is axis is periodic, else False.

Type:

numpy.ndarray of bool

property boundaries

Left and right boundary conditions as a tuple.

property boundaries_kind

Left and right boundary condition kind as a tuple.

classmethod default_boundaries_from_domain(boundaries)[source]
property discrete_fields

Return the dictionnary containing all the discretizations of this field.

discretize(topology, topology_state=None)[source]

Discretization of the field on a given topology.

Parameters:
  • topology (hysop.mpi.core.topology.Topology) – The topology on which to discretize this ScalarField.

  • state (hysop.mpi.core.topology.TopologyState, optional) – The topology state on which to discretize this ScalarField.

Return type:

The discretized field hysop.fields.discrete_field.DiscreteField.

Note

In the case the discretization already exists, simply returns the discretized field.

property dtype

Return the default allocation dtype of this ScalarField.

field_like(name, pretty_name=None, latex_name=None, var_name=None, domain=None, dtype=None, is_tmp=None, lboundaries=None, rboundaries=None, initial_values=None, **kwds)[source]

Create a ScalarField like this object, possibly altered.

property fields

Return all unique scalar fields contained in this field container.

format_boundaries()[source]
property initial_values

Return initial value of this field (compute_val, ghost_val).

property is_tensor
property is_tmp

Is this ScalarField a temporary field ?

property lboundaries

Left boundary conditions.

property lboundaries_kind

Left boundary condition kind.

long_description()[source]

Long description of this field.

property mem_tag
property nb_components

Total number of components of this field container, exluding None entries, but including duplicate fields.

property periodicity

Numpy array mask, True is axis is periodic, else False.

property rboundaries

Right boundary conditions.

property rboundaries_kind

Right boundary condition kind.

short_description()[source]

Short description of this field.

tmp_like(name, **kwds)[source]

Create a TemporaryField like self, possibly altered.

class hysop.fields.continuous_field.TensorField(domain, name, shape, pretty_name=None, name_formatter=None, pretty_name_formatter=None, skip_field=None, make_field=None, fields=None, base_kwds=None, **kwds)[source]

Bases: NamedTensorContainerI, FieldContainerI

A continuous tensor field is a collection of scalar fields defined on a physical domain, organized as a multi-dimensional array..

This object handles a numpy.ndarray of continuous scalar fields, which may have different attributes (different data types for example). It is mainly a view on scalar fields with the FieldContainerI interface.

A tensor field garanties that each different field objects have unique names and pretty names within the tensor field. A given continuous scalar field may appear in at multiple indices (to allow symetric tensor for example). Some components may also be set to None (to allow upper triangular matrices for example). Is also garanties that all fields shares the same domain.

Create an abstract named object that contains a symbolic value. name : string

A name for the field.

pretty_name: string, optional.

A pretty name used for display whenever possible. Defaults to name.

kwds: dict

Keywords arguments for base class.

classmethod default_make_field(idx, **kwds)[source]
classmethod default_name_formatter(basename, idx)[source]
classmethod default_pretty_name_formatter(basename, idx)[source]
classmethod default_skip_field(idx)[source]
discretize(topology, topology_state=None)[source]

Discretization of the field on a given topology.

Parameters:
  • topology (hysop.mpi.core.topology.Topology) – The topology on which to discretize this ScalarField.

  • state (hysop.mpi.core.topology.TopologyState, optional) – The topology state on which to discretize this ScalarField.

field_like(name, pretty_name=None, shape=None, nb_components=None, fn='field_like', **kwds)[source]

Create a TensorField like this object, possibly altered.

property fields

Return all unique scalar fields contained in this field-like interface.

classmethod from_field_array(name, fields, pretty_name=None, **kwds)[source]

Create a TensorField from numpy.ndarray of fields.

classmethod from_fields(name, fields, shape, pretty_name=None, **kwds)[source]

Create a TensorField from a list of fields and a shape.

property is_tensor
long_description()[source]

Long description of this tensor field as a string.

property nb_components

Total number of components of this field container, exluding None entries, but including duplicate fields.

short_description()[source]

Short description of this tensor field.

tmp_like(name, **kwds)[source]

Create a temporary field like self, possibly altered.

class hysop.fields.continuous_field.VectorField(domain, name, nb_components=None, shape=None, **kwds)[source]

Bases: TensorField

Specialization for vector fields, ie. a TensorField with ndim=1.

Create an abstract named object that contains a symbolic value. name : string

A name for the field.

pretty_name: string, optional.

A pretty name used for display whenever possible. Defaults to name.

kwds: dict

Keywords arguments for base class.

classmethod default_name_formatter(basename, idx)[source]